<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <%@include file="/res/include/base-head.jsp"%>
	<%@include file="/res/include/jquery-easyui.jsp"%>
	<%@include file="/res/include/umeditor.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath}/res/js/mall/supplier.js"></script>
  </head>
  <body>  
<div class="page_title clearfix">
    <h2>
    <c:if test="${!empty mallSupplierVo}">
    	编辑
    </c:if>
    <c:if test="${empty mallSupplierVo}">
    	新建
    </c:if>
    </h2>
</div>
<div class="form_item topic_add">
   <form id="data-form">
   	<c:if test="${!empty mallSupplierVo}">
    	<input type="hidden" name="id" value="${mallSupplierVo.id }"/>
    </c:if>
    <dl>
        <dt>类型：</dt>
        <dd>
        	<select name="type">
				<option value="1"
					<c:if test="${mallSupplierVo != null && mallSupplierVo.type==1}"> selected="selected"</c:if>
				>外部供应商</option>
				<option value="2"
					<c:if test="${mallSupplierVo != null && mallSupplierVo.type==2}"> selected="selected"</c:if>
				>本地供应商</option>
			</select>
        </dd>
    </dl>
    <dl>
        <dt>名称：</dt>
        <dd><input type="text" name="name" value="${mallSupplierVo.name }" class="txt grid-25 easyui-validatebox" data-options="required:true" maxlength="32"/></dd>
    </dl>
    <dl>
        <dt>简称：</dt>
        <dd><input type="text" name="shortName" value="${mallSupplierVo.shortName }" class="txt grid-25" maxlength="32"/></dd>
    </dl>
    <dl>
        <dt>供应商简介：</dt>
        <dd><input type="text" name="resume" value="${mallSupplierVo.resume }" class="txt grid-25" maxlength="32"/></dd>
    </dl>
    <dl>
        <dt>副标题：</dt>
        <dd><input type="text" name="subtitle" value="${mallSupplierVo.subtitle }" class="txt grid-25" maxlength="32"/></dd>
    </dl>
    <dl>
   		<dt>排序：</dt>
       	<dd><input type="text" class="txt grid-15 easyui-numberbox" precision="0" name="oidx" data-options="required:true" value="${mallSupplierVo.oidx }"/></dd>
    </dl>
    <dl>
    	<dt>详情页Logo：</dt>
        <dd>
        	<ul class="product_imglist logo_img">
	        	<c:choose>
	        	<c:when test="${!empty mallSupplierVo && !empty mallSupplierVo.logo}">
		        	<li>
		     			<a href="javascript:;" class="item" id="logoImg" onclick="admin.supplier.addImg('logoImg')"><p class="img"><img src="http://file.xfquanquan.com${mallSupplierVo.logo }" alt="" /></p></a>
		     			<em onclick="delLogoImg(this)"></em>
		     		</li>
	        	</c:when>
	        	<c:otherwise>
	        		<li><a href="javascript:;" class="item" id="logoImg" onclick="admin.supplier.addImg('logoImg')">添加图片</a></li>
	        	</c:otherwise>
	        	</c:choose>	
         	</ul>
        </dd>
    </dl>
    <dl>
    	<dt>详情页背景图：</dt>
        <dd>
        	<ul class="product_imglist bg_img">
        	    <c:choose>
	        	<c:when test="${!empty mallSupplierVo && !empty mallSupplierVo.bgImg}">
		        	<li>
        			<a href="javascript:;" class="item" id="bgImg" onclick="admin.supplier.addImg('bgImg')"><p class="img"><img src="http://file.xfquanquan.com${mallSupplierVo.bgImg }" alt="" /></p></a>
        			<em onclick="delBgImg(this)"></em>
        			</li>
	        	</c:when>
	        	<c:otherwise>
	        		<li><a href="javascript:;" class="item" id="bgImg" onclick="admin.supplier.addImg('bgImg')">添加图片</a></li>
	        	</c:otherwise>
	        	</c:choose>
         </ul>
        </dd>
    </dl>
    <dl>
        <dt>详情页超链接：</dt>
        <dd><input type="text" name="url" value="${mallSupplierVo.url }" class="txt grid-25" maxlength="32"/></dd>
    </dl>
    <dl>
        <dt>状态：</dt>
        <dd>
        	<select name="status">
				<option value="1"
					<c:if test="${mallSupplierVo != null && mallSupplierVo.status==1}"> selected="selected"</c:if>
				>有效</option>
				<option value="2"
					<c:if test="${mallSupplierVo != null && mallSupplierVo.status==2}"> selected="selected"</c:if>
				>失效</option>
			</select>
        </dd>
    </dl>
    <dl>
        <dt>是否首页展示：</dt>
        <dd>
        	<select name="isShow">
        	    <option value="2"
					<c:if test="${mallSupplierVo != null && mallSupplierVo.isShow==2}"> selected="selected"</c:if>
				>否</option>
				<option value="1"
					<c:if test="${mallSupplierVo != null && mallSupplierVo.isShow==1}"> selected="selected"</c:if>
				>是</option>
			</select>
        </dd>
    </dl>
    <dl>
    	<dt>首页轮播广告图：</dt>
        <dd>
        	<ul class="product_imglist banner_img">
        	    <c:choose>
	        	<c:when test="${!empty mallSupplierVo && !empty mallSupplierVo.banner}">
		        	<li>
        			<a href="javascript:;" class="item" id="bannerImg" onclick="admin.supplier.addImg('bannerImg')"><p class="img"><img src="http://file.xfquanquan.com${mallSupplierVo.banner }" alt="" /></p></a>
        			<em onclick="delBannerImg(this)"></em>
        			</li>
	        	</c:when>
	        	<c:otherwise>
	        		<li><a href="javascript:;" class="item" id="bannerImg" onclick="admin.supplier.addImg('bannerImg')">添加图片</a></li>
	        	</c:otherwise>
	        	</c:choose>
         </ul>
        </dd>
    </dl>
    <dl>
    	<dt>首页专栏广告图：</dt>
        <dd>
        	<ul class="product_imglist subject_img">
        	    <c:choose>
	        	<c:when test="${!empty mallSupplierVo && !empty mallSupplierVo.subjectImg}">
		        	<li>
        			<a href="javascript:;" class="item" id="subjectImg" onclick="admin.supplier.addImg('subjectImg')"><p class="img"><img src="http://file.xfquanquan.com${mallSupplierVo.subjectImg }" alt="" /></p></a>
        			<em onclick="delSubjectImg(this)"></em>
        			</li>
	        	</c:when>
	        	<c:otherwise>
	        		<li><a href="javascript:;" class="item" id="subjectImg" onclick="admin.supplier.addImg('subjectImg')">添加图片</a></li>
	        	</c:otherwise>
	        	</c:choose>
         </ul>
        </dd>
    </dl>
    <dl>
    	<dt>供应商（社区门店）首图：</dt>
        <dd>
        	<ul class="product_imglist first_img">
        	    <c:choose>
	        	<c:when test="${!empty mallSupplierVo && !empty mallSupplierVo.firstImg}">
		        	<li>
        			<a href="javascript:;" class="item" id="firstImg" onclick="admin.supplier.addImg('firstImg')"><p class="img"><img src="http://file.xfquanquan.com${mallSupplierVo.firstImg }" alt="" /></p></a>
        			<em onclick="delFirstImg(this)"></em>
        			</li>
	        	</c:when>
	        	<c:otherwise>
	        		<li><a href="javascript:;" class="item" id="firstImg" onclick="admin.supplier.addImg('firstImg')">添加图片</a></li>
	        	</c:otherwise>
	        	</c:choose>
         </ul>
        </dd>
    </dl>
    <dl>
      	<dt>详情页介绍图片：</dt>
          <dd>
          	<ul class="product_imglist resumeImg_imglist">
          		<c:set var="rImgCount" value="1" />
          		<c:forTokens items="${mallSupplierVo.resumeImg}" delims=";" var="rImg" varStatus="status"> 
          			<c:set var="rImgCount" value="${status.count}" />
          			<li>
          			<a href="javascript:;" class="item" id="resumeImg${status.index+1}" onclick="admin.supplier.addImg('resumeImg${status.index+1}')"><p class="img"><img src="http://file.xfquanquan.com${rImg }" alt="" /></p></a>
          			<em onclick="delResumeImg(this,${status.index+1})"></em>
          			</li>
          		</c:forTokens>
          		<c:forEach begin="${rImgCount}" end="10" step="1" varStatus="i">
          			<li><a href="javascript:;" class="item" id="resumeImg${i.index+1+rImgCount}" onclick="admin.supplier.addImg('resumeImg${i.index+1+rImgCount}')">添加图片</a></li>
          		</c:forEach>
           </ul>
           <em class="p0">上传4:3的JPG/PNG/BMP图片，建议：720*540px</em>
          </dd>
      </dl>
    <dl>
        <dt>社区：</dt>
        <dd><input type="text" id="communityName" value="${mallSupplierVo.communityName }" class="txt grid-25" maxlength="32" readonly="readonly" onclick="admin.supplier.chooseCommunity()"/>本地供应商需要设置所在社区</dd>
        <input type="hidden" id="communityId" name="communityId" value="${mallSupplierVo.communityId }"/>
    </dl>
    <dl>
        <dt>关联用户：</dt>
        <dd><input type="text" id="userInfo" value="${mallSupplierVo.userInfo }" class="txt grid-25" maxlength="32" readonly="readonly" onclick="admin.supplier.chooseUser()"/>本地供应商需要设置关联的前台用户</dd>
        <input type="hidden" id="userId" name="userId" value="${mallSupplierVo.userId }"/>
    </dl>
    <dl>
        <dt>地址：</dt>
        <dd><input type="text" id="address" name="address" value="${mallSupplierVo.address }" class="txt grid-25" maxlength="64" /></dd>
    </dl>
    <dl>
        <dt>电话：</dt>
        <dd><input type="text" id="phone" name="phone" value="${mallSupplierVo.phone }" class="txt grid-25" maxlength="32" /></dd>
    </dl>
    <dl>
        <dt>分账比例：</dt>
        <dd><input type="text" id="rate" name="rate" value="${mallSupplierVo.rate }" class="txt grid-15 easyui-numberbox" min="0.00" max="1.50" precision="2" data-options="required:true" maxlength="5" /></dd>
    </dl>
     <!--   <dl>
        <dt>描述：</dt>
        <dd>
        	<script id="container" name="resume" type="text/plain" style="width:480px;height:150px;">${mallSupplierVo.resume}</script>
			    <script type="text/javascript">
			    	window.UMEDITOR_HOME_URL='${pageContext.request.contextPath}/res/lib/umeditor/';
			        var um = UM.getEditor('container');
			    </script>
        </dd>
    </dl>-->
    </form>
    <p class="page_btn"><input type="button" id="doSave" value="保存" class="btn_blue" onclick="doSave();"/></p>
</div>
<script type="text/javascript">
var qlevel = 1;

var isSave = false;
//提交保存
function doSave(){
	var logoImg = "";
	var logoImglist = $(".logo_img img");
	if (logoImglist && logoImglist.length > 0) {
		logoImglist.each(function(){
		    if (logoImg == "") {
		    	logoImg += $(this).attr("src").replace(imgFilePath,"");
		    } else {
		    	logoImg += ";" + $(this).attr("src").replace(imgFilePath,"");
		    }
		});
	}
	
	var bgImg = "";
	var bgImglist = $(".bg_img img");
	if (bgImglist && bgImglist.length > 0) {
		bgImglist.each(function(){
		    if (bgImg == "") {
		    	bgImg += $(this).attr("src").replace(imgFilePath,"");
		    } else {
		    	bgImg += ";" + $(this).attr("src").replace(imgFilePath,"");
		    }
		});
	}
	
	var bannerImg = "";
	var bannerImglist = $(".banner_img img");
	if (bannerImglist && bannerImglist.length > 0) {
		bannerImglist.each(function(){
		    if (bannerImg == "") {
		    	bannerImg += $(this).attr("src").replace(imgFilePath,"");
		    } else {
		    	bannerImg += ";" + $(this).attr("src").replace(imgFilePath,"");
		    }
		});
	}
	
	
	var resumeImg = "";
	var resumeImglist = $(".resumeImg_imglist img");
	if (resumeImglist && resumeImglist.length > 0) {
		resumeImglist.each(function(){
		    if (resumeImg == "") {
		    	resumeImg += $(this).attr("src").replace(imgFilePath,"");
		    } else {
		    	resumeImg += ";" + $(this).attr("src").replace(imgFilePath,"");
		    }
		});
	}
	
	var subjectImg = "";
	var subjectImglist = $(".subject_img img");
	if (subjectImglist && subjectImglist.length > 0) {
		subjectImglist.each(function(){
		    if (subjectImg == "") {
		    	subjectImg += $(this).attr("src").replace(imgFilePath,"");
		    } else {
		    	subjectImg += ";" + $(this).attr("src").replace(imgFilePath,"");
		    }
		});
	}
	
	var firstImg = "";
	var firstImglist = $(".first_img img");
	if (firstImglist && firstImglist.length > 0) {
		firstImglist.each(function(){
		    if (firstImg == "") {
		    	firstImg += $(this).attr("src").replace(imgFilePath,"");
		    } else {
		    	firstImg += ";" + $(this).attr("src").replace(imgFilePath,"");
		    }
		});
	}
	
	var url = contextPath+'/mall/supplier/add';
	<c:if test="${!empty mallSupplierVo}">
		url = contextPath+'/mall/supplier/update';
	</c:if>
	if(!$('#data-form').form('validate')) return;
	if (isSave) {
		return;
	}
	isSave = true;
	var data = $('#data-form').form('jsonObject');
	data.logo = logoImg;
	data.bgImg = bgImg;
	data.banner = bannerImg;
	data.resumeImg = resumeImg;
	data.subjectImg = subjectImg;
	data.firstImg = firstImg;
	//console.info("------------:"+JSON.stringify(data));
	$.post(url,data,function(result) {
		if(result.code==1) {
			top.showInfo('保存成功');
		} else {
			isSave = false;
			top.showInfo('保存失败:'+result.msg);
		}
	},'json');
}

function delLogoImg(obj,index){
	$(obj).closest('li').html('<a href="javascript:;" class="item" id="logoImg" onclick="admin.supplier.addImg(\'logoImg\')">添加图片</a>');
}
function delBgImg(obj,index){
	$(obj).closest('li').html('<a href="javascript:;" class="item" id="bgImg" onclick="admin.supplier.addImg(\'bgImg\')">添加图片</a>');
}
function delBannerImg(obj,index){
	$(obj).closest('li').html('<a href="javascript:;" class="item" id="bannerImg" onclick="admin.supplier.addImg(\'bannerImg\')">添加图片</a>');
}
function delResumeImg(obj,index){
	$(obj).closest('li').html('<a href="javascript:;" class="item" id="resumeImg'+index+'" onclick="admin.supplier.addImg("resumeImg'+index+'")">添加图片</a>');
}
function delSubjectImg(obj,index){
	$(obj).closest('li').html('<a href="javascript:;" class="item" id="subjectImg" onclick="admin.supplier.addImg(\'subjectImg\')">添加图片</a>');
}
function delFirstImg(obj,index){
	$(obj).closest('li').html('<a href="javascript:;" class="item" id="firstImg" onclick="admin.supplier.addImg(\'firstImg\')">添加图片</a>');
}
</script>
  </body>
</html>
